<?php
namespace UserProposal;
use UserProposal\Proposal;
use Users\Helper\SmartRedirect;
/**
 * Общее действие выбирающее очередное предложение на модерацию
 * @author kosh
 *
 */
abstract class StackAction extends \Action {
    protected static $isPublic = true;
    
	protected static $layout = "#layouts.common";
	
	static function pullParams() {
		return ['identity'];
	}
	
	protected function run() {
		
		// запоминаем адрес, куда должны будем вернуться после вынесения решения
		
		$redirectParams = $this->request->params();
		unset($redirectParams['_identity']);
		$redirectUrl = $this->url($this->request->action, $redirectParams);
		SmartRedirect::clearRedirectPoint('to-user-proposal-stack');
		SmartRedirect::rememberRedirectPoint($redirectUrl, 'to-user-proposal-stack');
		
		
		if ($this->request->type) {
			$proposalType = explode(',', $this->request->type);

			if (!empty($proposalType)) 
			{
				$type = $proposalType;
			}
			else 
			{
				$type = null;
			}
		}
	
		$proposal = Proposal::getForSurvey($this->request->_identity, $type, $this->request->problemType);

		if ($proposal) {
			$config = $proposal->getConfig();
			$this->response->proposal = $proposal;
			$this->response->type = $this->request->type;
			$this->response->action = $config['surveyAction'];
		}
	}
} 